Complete Implementation
The following are the reference codes for JoinDAO and GetAllProposals. You can check if your implementation matches the reference codes.
Implementing Join DAO Function
Check if the passed Address parameter has already joined the DAO. We query State.Members based on the passed address and use the Assert method for verification.
If the address has not yet joined the DAO, add the address to State.Members and set its value to true.
Read the current value of State.MemberCount, increment it by 1, and assign the new value to State.MemberCount.
public override Empty JoinDAO(Address input)
{
// Based on the address, determine whether the address has joined the DAO. If it has, throw an exception
Assert(!State.Members[input], "Member is already in the DAO");
// If the address has not joined the DAO, then join and update the state's value to true
State.Members[input] = true;
// Read the value of MemberCount in the state, increment it by 1, and update it in the state
var currentCount = State.MemberCount.Value;
State.MemberCount.Value = currentCount + 1;
return new Empty();
}
Implementing Get All Proposals Function
Create a list object named ProposalList.
Starting from 0, loop until the value of State.NextProposalId is reached. Within the loop, sequentially retrieve the corresponding values from State.Proposals and add them to ProposalList. Finally, return ProposalList.
public override ProposalList GetAllProposals(Empty input)
{
// Create a new list called ProposalList
var proposals = new ProposalList();
// Start iterating through Proposals from index 0 until the value of NextProposalId, read the corresponding proposal, add it to ProposalList, and finally return ProposalList
for (var i = 0; i < State.NextProposalId.Value; i++)
{
var proposalCount = i.ToString();
var proposal = State.Proposals[proposalCount];
proposals.Proposals.Add(proposal);
}
return proposals;
}
When you have completed the implementation of these two methods and run the unit tests again, you should see that all test cases have passed.